package edu.gatech.cs2340.teamrocket.model.pokemon.ailments;

import edu.gatech.cs2340.teamrocket.model.pokemon.Pokemon;

/**
 * Represents a Confusion status ailment.
 *
 * @author Joe Tacheron
 */
public class Confusion implements Ailment {

    private static final int DAMAGE = 20;
    private static final double HURT_PROB = 0.5;

    private int turns;

    public Confusion(){
        turns = 1 + (int)(Math.random() * 3);
    }

    /**
     * Affect the Pokemon for 1-3 turns. 50% chance it will take 20 damage.
     *
     * @param t
     * @return
     */
    @Override
    public String affect(Pokemon t) {
        turns--;
        if(turns < 0){
            t.setAilment(AilmentFactory.NONE);
            return healMessage(t);
        }
        if(Math.random() < HURT_PROB){
            t.takeDamage(DAMAGE);
            if(t.isFainted())
                return faintMessage(t);
            else
                return hurtMessage(t);
        }
        return null;
    }

    @Override
    public String catchMessage(Pokemon t) {
        return t + " is now confused!";
    }

    @Override
    public String healMessage(Pokemon t) {
        return t + " snapped out of confusion!";
    }

    @Override
    public String faintMessage(Pokemon t) {
        return t + " is now confused!";
    }

    /**
     *
     * @return true
     */
    @Override
    public boolean healedByFullHeal() {
        return true;
    }

    @Override
    public String hurtMessage(Pokemon t) {
        return t + " hurt itself in its confusion!";
    }

    /**
     *
     * @return "CNF" colored orange
     */
    @Override
    public String statusString() {
        return "<span color='#FFA500'>CNF</span>";
    }
}
